package com.unknown.wiki.details.viewModel;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;

import com.unknown.wiki.base.BaseViewModel;
import com.unknown.wiki.details.WikiDetailsContract;
import com.unknown.wiki.details.repository.WikiDetailsRepository;
import com.unknown.wiki.model.Wiki;

public class WikiDetailsViewModel extends BaseViewModel implements WikiDetailsContract.IWikiDetailsViewModel {
    private WikiDetailsContract.IWikiDetailsRepository wikiDetailsRepository;

    public WikiDetailsViewModel() {
        wikiDetailsRepository = new WikiDetailsRepository();
    }

    @Override
    public LiveData<Wiki> getWiki(String wikiId) {
        MutableLiveData<Wiki> mutableLiveData = new MutableLiveData<>();
        wikiDetailsRepository.getWiki(wikiId, data -> commonOnSuccessListener(mutableLiveData, data),
                throwable -> commonOnFailureListener(mutableLiveData, throwable));
        return mutableLiveData;
    }
}
